// 数据格式
// [{ count: number, time: string }]

// const padZero = (num: number): string => {
const padZero: (num: number) => string = (num) => {
  return num.toString().padStart(2, '0')
}

// !1. 封装一个格式化日期的函数
const formatTime = (date?: Date | string): string => {
  // 如果不传，就当前的时间
  if(!date) date = new Date()
  // 如果传了字符串，转为日期对象
  if(typeof date === 'string') date = new Date(date)
  
  let year = date.getFullYear()
  let month = date.getMonth() + 1
  let ri = date.getDate()
  let hours = date.getHours()
  let minutes = date.getMinutes()
  let seconds = date.getSeconds()

  return `${year}-${padZero(month)}-${padZero(ri)} ${padZero(hours)}:${padZero(minutes)}:${padZero(seconds)}`
}

console.log(formatTime()) // 不传参数，返回当前的日期
console.log(formatTime('2023-6-6')) // 支持
console.log(formatTime(new Date('2023-6-6'))) // 当前的年月日，2023-6-6 8:7:5

export {}